﻿namespace NetEasyMusic.Lib.Operations;

public static class ImageOpera
{
    public static async Task<byte[]> GetImage(string url, int x = 50, int y = 50)
    {
        try
        {
            using var sharedClient = new HttpClient();
            url = $"{url}?param={y}y{x}";
            var context = await sharedClient.GetAsync(url);
            return await context.Content.ReadAsByteArrayAsync();
        }
        catch
        {
            return Array.Empty<byte>();
        }
    }

    public static async Task<Stream> GetImageStream(string url, int x = 50, int y = 50)
    {
        try
        {
            using var sharedClient = new HttpClient();
            url = $"{url}?param={y}y{x}";
            var context = await sharedClient.GetAsync(url);
            return await context.Content.ReadAsStreamAsync();
        }
        catch 
        {
            return Stream.Null;
        }
    }
}